package com.jingzhi.count.controller;

import com.jingzhi.count.entity.MyResponse;
import com.jingzhi.count.entity.Note;
import com.jingzhi.count.mapper.NoteMapper;
import com.jingzhi.count.utils.TimeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


/**
 * 作者： 张恒同
 * 时间： 2018/3/23   13:02
 * 描述： 记录
 */
@RestController
public class NoteController extends BaseController {

    @Autowired
    private  NoteMapper  noteMapper;

    @GetMapping(value = "/addNote.do")
    public ResponseEntity<MyResponse> postNote(@RequestParam(value = "prod_id", required = false, defaultValue = "0") int prod_id,
                                               @RequestParam(value = "sensor_id", required = false, defaultValue = "0") int sensor_id){

        Note note = new Note();
        note.setSensorId(String.valueOf(sensor_id));
        note.setTimeStamp(TimeUtils.getTimeStamp());

        logger.debug("controller ");
        logger.info("服务端接收数据 - " + sensor_id);

        noteMapper.insert(note);

        MyResponse response = new MyResponse();
        response.setRc(0);
        response.setDes("不错哦~");

        return new ResponseEntity<>(response, HttpStatus.OK);
    }

}
